Skip to content

Conversation

koheiw
Copy link

@koheiw koheiw commented Jun 17, 2025

This PR adds stat_ksmooth() to smooth data points using stats::ksmooth().

library(ggplot2)
ggplot(economics, aes(date, psavert)) +
  geom_point(alpha = 0.25) +
  stat_ksmooth(bandwidth = 180, kernel = "normal")  

image

@teunbrand
Copy link
Collaborator

Hi Kohei, thank you for preparing this PR! This seems like a useful stat to add to an extension package somewhere. It is our policy to not admit any new geoms or stats to ggplot2 itself because it would grow to unmaintainable proportions (unless they are widely applicable novelties). To accommodate innovation in this area, the extension system was designed for exactly cases such as stat_ksmooth().

You are most welcome to host it in a package of your own, but if you have trouble finding a home for this stat, we could consider putting it in ggh4x. It already hosts a related stat_rollingkernel().

library(ggplot2)
ggplot(economics, aes(date, psavert)) +
  geom_point(alpha = 0.25) +
  ggh4x::stat_rollingkernel(bw = 90)

Created on 2025-09-24 with reprex v2.1.1

@teunbrand teunbrand closed this Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants